using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;

namespace DanMuHelper.Logging
{
    /// <summary>
    /// MonoBehaviour日志, 隐含InContext
    /// </summary>
    public static class MbrLog
    {
        [Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
        public static void LogInfo(this UnityEngine.MonoBehaviour context, object message,
            [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")
        {
            Echo.WriteInContext(Echo.EchoType.Info, context, message, callerFilePath, callerMemberName);
        }

        [Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
        public static void LogInfoRich(this UnityEngine.MonoBehaviour context, object message, string color,
            [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")
        {
            Echo.WriteRichInContext(Echo.EchoType.Info, color, context, message, callerFilePath, callerMemberName);
        }

        [Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
        public static void LogInfoRich(this UnityEngine.MonoBehaviour context, object message, Color color,
            [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")
        {
            Echo.WriteRichInContext(Echo.EchoType.Info, "#" + ColorUtility.ToHtmlStringRGB(color), context, message, callerFilePath, callerMemberName);
        }

        [Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
        public static void LogInfoFormat(this UnityEngine.MonoBehaviour context, string format, params object[] args)
        {
            Echo.WriteInContext(Echo.EchoType.Info, context, string.Format(format, args));
        }

        [Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
        public static void LogInfoFormatRich(this UnityEngine.MonoBehaviour context, string color, string format, params object[] args)
        {
            Echo.WriteRichInContext(Echo.EchoType.Info, color, context, string.Format(format, args));
        }

        [Conditional("UNITY_EDITOR"), Conditional("DEVELOPMENT_BUILD")]
        public static void LogInfoFormatRich(this UnityEngine.MonoBehaviour context, Color color, string format, params object[] args)
        {
            Echo.WriteRichInContext(Echo.EchoType.Info, "#" + ColorUtility.ToHtmlStringRGB(color), context, string.Format(format, args));
        }

        public static void LogWarning(this UnityEngine.MonoBehaviour context, object message,
            [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")
        {
            Echo.WriteInContext(Echo.EchoType.Warning, context, message, callerFilePath, callerMemberName);
        }

        public static void LogWarningFormat(this UnityEngine.MonoBehaviour context, string format, params object[] args)
        {
            Echo.WriteInContext(Echo.EchoType.Warning, context, string.Format(format, args));
        }

        public static void LogError(this UnityEngine.MonoBehaviour context, object message,
            [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")
        {
            Echo.WriteInContext(Echo.EchoType.Error, context, message, callerFilePath, callerMemberName);
        }

        public static void LogErrorFormat(this UnityEngine.MonoBehaviour context, string format, params object[] args)
        {
            Echo.WriteInContext(Echo.EchoType.Error, context, string.Format(format, args));
        }

        public static void LogException(this UnityEngine.MonoBehaviour context, System.Exception message,
            [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")
        {
            Echo.WriteInContext(Echo.EchoType.Error, context, message, callerFilePath, callerMemberName);
        }
    }
}
